﻿using System;

namespace UniRx.Operators
{
	// Token: 0x02000370 RID: 880
	internal class ZipLatestObservable<T1, T2, T3, T4, TR> : OperatorObservableBase<TR>
	{
		// Token: 0x060011F6 RID: 4598 RVA: 0x00052314 File Offset: 0x00050714
		public ZipLatestObservable(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, ZipLatestFunc<T1, T2, T3, T4, TR> resultSelector) : base(source1.IsRequiredSubscribeOnCurrentThread<T1>() || source2.IsRequiredSubscribeOnCurrentThread<T2>() || source3.IsRequiredSubscribeOnCurrentThread<T3>() || source4.IsRequiredSubscribeOnCurrentThread<T4>())
		{
			this.source1 = source1;
			this.source2 = source2;
			this.source3 = source3;
			this.source4 = source4;
			this.resultSelector = resultSelector;
		}

		// Token: 0x060011F7 RID: 4599 RVA: 0x0005237D File Offset: 0x0005077D
		protected override IDisposable SubscribeCore(IObserver<TR> observer, IDisposable cancel)
		{
			return new ZipLatestObservable<T1, T2, T3, T4, TR>.ZipLatest(4, this, observer, cancel).Run();
		}

		// Token: 0x04000AB6 RID: 2742
		private IObservable<T1> source1;

		// Token: 0x04000AB7 RID: 2743
		private IObservable<T2> source2;

		// Token: 0x04000AB8 RID: 2744
		private IObservable<T3> source3;

		// Token: 0x04000AB9 RID: 2745
		private IObservable<T4> source4;

		// Token: 0x04000ABA RID: 2746
		private ZipLatestFunc<T1, T2, T3, T4, TR> resultSelector;

		// Token: 0x02000371 RID: 881
		private class ZipLatest : NthZipLatestObserverBase<TR>
		{
			// Token: 0x060011F8 RID: 4600 RVA: 0x0005238D File Offset: 0x0005078D
			public ZipLatest(int length, ZipLatestObservable<T1, T2, T3, T4, TR> parent, IObserver<TR> observer, IDisposable cancel) : base(length, observer, cancel)
			{
				this.parent = parent;
			}

			// Token: 0x060011F9 RID: 4601 RVA: 0x000523AC File Offset: 0x000507AC
			public IDisposable Run()
			{
				this.c1 = new ZipLatestObserver<T1>(this.gate, this, 0);
				this.c2 = new ZipLatestObserver<T2>(this.gate, this, 1);
				this.c3 = new ZipLatestObserver<T3>(this.gate, this, 2);
				this.c4 = new ZipLatestObserver<T4>(this.gate, this, 3);
				//IDisposable disposable = this.parent.source1.Subscribe(this.c1);
				//IDisposable disposable2 = this.parent.source2.Subscribe(this.c2);
				//IDisposable disposable3 = this.parent.source3.Subscribe(this.c3);
				//IDisposable disposable4 = this.parent.source4.Subscribe(this.c4);
				//return StableCompositeDisposable.Create(disposable, disposable2, disposable3, disposable4);
				return null;
			}

			// Token: 0x060011FA RID: 4602 RVA: 0x0005246A File Offset: 0x0005086A
			public override TR GetResult()
			{
				return this.parent.resultSelector(this.c1.Value, this.c2.Value, this.c3.Value, this.c4.Value);
			}

			// Token: 0x060011FB RID: 4603 RVA: 0x000524A8 File Offset: 0x000508A8
			public override void OnNext(TR value)
			{
				this.observer.OnNext(value);
			}

			// Token: 0x060011FC RID: 4604 RVA: 0x000524B8 File Offset: 0x000508B8
			public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x060011FD RID: 4605 RVA: 0x000524F0 File Offset: 0x000508F0
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x04000ABB RID: 2747
			private readonly ZipLatestObservable<T1, T2, T3, T4, TR> parent;

			// Token: 0x04000ABC RID: 2748
			private readonly object gate = new object();

			// Token: 0x04000ABD RID: 2749
			private ZipLatestObserver<T1> c1;

			// Token: 0x04000ABE RID: 2750
			private ZipLatestObserver<T2> c2;

			// Token: 0x04000ABF RID: 2751
			private ZipLatestObserver<T3> c3;

			// Token: 0x04000AC0 RID: 2752
			private ZipLatestObserver<T4> c4;
		}
	}
}
